<!--
 * @Description: 地图
 * @Author: charles
 * @Date: 2021-05-05 23:34:12
 * @LastEditors: lk
 * @LastEditTime: 2022-01-10 20:59:36
-->
<template>
  <div ref="map_container" style="height: 95%"></div>
</template>

<script>
export default {
    data() {
        return {

        }  
    },
    mounted(){
        this.initMap();
    },
    methods:{
        initMap(){
            var map = new AMap.Map(this.$refs.map_container, {
            zoom:11,//级别
            center: [112.578781,37.813948],//中心点坐标
            viewMode:'3D'//使用3D视图
        });
      let polygons=[];
      var opts = {
          subdistrict: 0,   //获取边界不需要返回下级行政区
          extensions: 'all',  //返回行政区边界坐标组等具体信息
          level: 'district'  //查询行政级别为 市
      };
      let district = new AMap.DistrictSearch(opts);
      district.setExtensions('all');
      district.search('太原市', function(status, result) {
          map.remove(polygons)//清除上次结果
          polygons = [];
          var bounds = result.districtList[0].boundaries;
          if (bounds) {
              for (var i = 0, l = bounds.length; i < l; i++) {
                  //生成行政区划polygon
                  var polygon = new AMap.Polygon({
                      strokeWeight: 3,
                      path: bounds[i],
                      fillOpacity: 0.4,
                      fillColor: '#80d8ff',
                      strokeColor: '#0091ea'
                  });
                  polygons.push(polygon);
              }
          }
          map.add(polygons)
          map.setFitView(polygons);//视口自适应
      });

      var marker1 =new AMap.Marker({
        icon: '//vdata.amap.com/icons/b18/1/2.png',
        position:[112.549656,37.870451],
        title:'太原市',
      });
      map.add(marker1);
      var marker2 =new AMap.Marker({
        position:[112.752633,37.688006],
        title:'晋中市',
      });
      map.add(marker2);
      var marker3 =new AMap.Marker({
        position:[113.580426,37.857094],
        title:'阳泉市',
      });
      map.add(marker3);
        }
    }
}
</script>

